home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Learn Microsoft Visual Basic 6.0 Now
/
Learn Microsoft Visual Basic 6.0 Now (Microsoft Press)(X03-58607)(1998).ISO
/
media
/
chap02
/
b02d015.cc2
< prev
next >
Wrap
Text File
|
1998-06-07
|
5KB
|
105 lines
0, When you write programs that interact
2, with the user you'll want to use input
5, controls that present choices and receive
7, user input. I created this online shopper
10, program to demonstrate four input
12, controls you may want to use: the option
15, button control, the checkbox control, the
18, listbox control, and the combobox control.
22, An option button displays a list of
24, choices, but requires that you choose only
27, one. In this program every choice I make
30, is displayed graphically on the right
32, side so that you can see immediately
34, what's going on. A collection of checkboxes
39, allows you to choose one or more
42, choices. And if you choose you can choose no
46, choices. Checkboxes allow you a lot of
49, flexibility in gathering input. A listbox
53, allows you to choose one choice and only
55, one choice from a list. And if you like,
58, you can have a default choice. Finally,
61, a combobox is a compact listbox that
64, displays one or more choices and gives you
67, an opportunity for a default. Now that
71, you've had a chance to see the input
72, controls in action let's examine the
75, program code that makes them work. I'll stop
80, the program and double-click the
83, answering machine checkbox to look at the
87, program code that processes all the
91, checkboxes. The check1_click event procedure
95, contains the program code that runs when the
97, user clicks the answering machine
99, checkbox in the program. The important keyword
104, here is check1.value, which should be
109, read as the value property of the first
111, checkbox object. Check1 is the name of
114, the first checkbox created on the form.
117, And subsequent checkboxes were check2,
119, check3, and so on. The value property is a
124, property that changes when a user clicks
126, the checkbox on the form. When an x or
131, a checkmark appears in the checkbox the
133, value of the property is set to 1. If
136, the checkbox is blank the value property
138, is set to 0. In this case, if the
141, property evaluates to 1 the program loads a
145, picture of an answering machine into the
147, second image box on the form and makes the
150, picture visible. Otherwise, if the
155, value property is 0 then a picture is
159, removed from that image box on the form. If
163, this all seems a little bit odd don't
164, worry, you'll learn more about if and
166, decision structures in Chapter 5. Now I'll
171, close the code window and double-click the
174, peripherals listbox on the form. Here,
177, you'll see code that executes when the
179, user clicks an item in the peripheral
181, listbox. In this case, the important keyword
184, is list1.listIndex, which is read as
188, the list index property in the first list
191, object. After the user makes a selection
194, in the listbox, the list index property
197, returns a number that corresponds to
199, the location of the item in the listbox.
203, The first item is numbered 0. The second
206, item is numbered 1 and so on. The actual
209, text of the choice is also returned in
211, the list1.text property. Visual Basic
215, programmers often use this value in their
218, programs, although I didn't choose to
220, use it here. Now I'll close the code
222, window and double-click the form itself to
229, show the code that is associated with the
231, form when it is first loaded and run.
234, This is called the form load event
235, procedure, and is executed the first time that
239, the form loads, usually at the very
241, beginning of the program. Programmers put
243, special statements in this special
245, procedure if they want them executed every time
247, a program starts. As in the online
250, shopper program, the statements often
253, reflect or define an aspect of the user
255, interface that couldn't be created using the
258, toolbox controls and the properties
259, window. The first line holds a statement that
264, loads the personal computer window's
266, metafile into the picture property of the
269, image1 object. The next three lines add
272, the items to the peripherals listbox,
275, the list1 object in the program. The key
278, method here is addItem, which will add an
280, item to either the listbox, or below,
284, items can be added to the combobox. So
290, we've seen how option buttons, checkboxes,
292, and listboxes, along with comboboxes,
295, are created in a program. To learn more
298, about the program code and the online
300, shopper program itself load the demo 2-3
304, program in your Learn Visual Basic Now
305, sample file directory and play around with
307, it a little bit.
309, END